{% from "macros/forms.html" import form_input, form_switch %}
{% from "macros/datatable.html" import datatable %}
{% set columns = [{'title': 'Name', 'field': 'name', 'sortable': True, 'searchable': True}, {'title': 'ID', 'field': 'id', 'sortable': True, 'searchable': True}] %}
{% set osint_sources = osint_sources | default([]) | tojson %}
{% set word_lists = word_lists | default([]) | tojson %}

{% set form_error = form_error | default({}) %}
<div class="bg-base-100 p-4">
  <h1 class="text-3xl font-bold mb-5 w-3/4 ml-[10%]">{{ submit_text }}</h1>
  <p class="text-base-content/60 text-[0.7rem] mb-5 w-1/2 ml-[10%]">ID: {{ osint_source_group.id }}</p>

  <form id="{{ model_name }}-form"
        class="w-1/2 ml-[10%]"
        {{ form_action }}
        hx-swap="innerHTML"
        hx-target="#form-container"
        hx-target-error="#form-container">
    {% include "partials/admin_form_error.html" %}
    {{ form_input('Name', 'name', osint_source_group.name, form_error.name) }}
    {{ form_input('Description', 'description', osint_source_group.description, form_error.description, required=False) }}
    {{ form_switch('Default', 'default', osint_source_group.default, yes_val=True, no_val=False, required=False, width='w-1/4', disabled=True) }}

    {{ datatable(table_id='osint_sources', data=osint_sources, columns=columns, selected_items=osint_source_group.osint_sources, selectable=true, input_name="osint_sources[]", headline="OSINT Sources") }}
    {{ datatable(table_id='word_lists', data=word_lists, columns=columns, selected_items=osint_source_group.word_lists, selectable=true, input_name="word_lists[]", headline="Word Lists") }}
    <input type="submit" class="btn btn-primary mt-5 w-full" value="{{ submit_text }}" />
  </form>
</div>
